package com.woniu.project.controller;

import com.woniu.project.core.dto.ResultDto;
import com.woniu.project.core.exception.ProjectProductException;
import com.woniu.project.service.UploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/upload")
@Api(tags="文件上传")
public class UploadController {
    @Autowired
    UploadService uploadService;
    @ApiOperation(value="图标上传",notes = "传入文件")
    @PostMapping("/iconUpload")
    public ResultDto iconUpload(MultipartFile file) {
        try {
            String addr = uploadService.iconUpload(file);
            return ResultDto.success(200, "图标上传成功", addr);
        } catch (Exception e) {
            e.printStackTrace();
            throw new ProjectProductException(500, "图标上传系统异常");
        }
    }
}
